﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PlayBox
{
    public partial class StartGUI : Form
    {
        public StartGUI()
        {
            InitializeComponent();
            this.Load += new EventHandler(StartGUI_Load);
        }

        void StartGUI_Load(object sender, EventArgs e)
        {
            // TODO: Hier Server eintragen
            ServerConnection.Create(Properties.Settings.Default.BaseServerAddress);

            /* just test code */
         /*   DataClasses.Music music;
            
            music = new DataClasses.Music();
            music.SongStream = music.getTestStream();
            music.ID = "test123";
            music.SaveToDisk();
            
            //return;
            
            music = new DataClasses.Music();
            music.InitFromDisk("test123");

            music.Title = "Test";
            music.Artist = "Tester";
            music.Play();
            
            DataClasses.TPM.generateUserKey("Norbert");
            byte[] key = DataClasses.TPM.getUserKey("Norbert");*/

            /* test code end */

            LoginUser();
        }

        void LoginUser ()
        {
            this.Visible = false;

            // -------------------------
            // Normal einloggen
            // -------------------------

            if (!User.LogInLastUser())
            { 
                var login = new Login();
                login.ShowDialog();

                // Wenn nicht erfolgreich, beenden
                if (!User.IsLoggedIn)
                {
                    Environment.Exit(0);
                    return;
                }
            }

            this.Visible = true;
        }

        private void abmeldenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            User.LogOut();
            LoginUser();
        }

        private void beendenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            User.LogOut();
            this.Close();
        }

        private void passwortÄndernToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var cp = new ChangePassword();
            cp.ShowDialog();
        }
    }
}
